package com.kinghunt.misp.service.impl.regionx;

import com.bygoodtech.kings.base.utils.ConvertUtil;
import com.bygoodtech.kings.common.dto.ApiResult;
import com.kinghunt.misp.common.dto.regionx.SysRegionDTO;
import com.kinghunt.misp.dal.dao.regionx.SysRegionDAO;
import com.kinghunt.misp.dal.model.regionx.SysRegionDO;
import com.kinghunt.misp.service.api.regionx.SysRegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 地区管理
 *
 * @Author ciaran
 * @Date 2023/7/13 21:58l
 */
@Slf4j
@Service
@Transactional
public class SysRegionServiceImpl implements SysRegionService {

    @Autowired(required = false)
    private SysRegionDAO regionDAO;

    @Override
    public ApiResult<List<SysRegionDTO>> getSysRegionByParentId(String id) {
        if (StringUtils.isEmpty(id)) {
            id = "-1";
        }
        List<SysRegionDO> sysRegionDO = regionDAO.selectSysRegionByParentId(id);
        List<SysRegionDTO> dto =  ConvertUtil.convert(sysRegionDO, SysRegionDTO.class);
        return ApiResult.ok(dto);
    }
}
